﻿#ifndef OPENGLWINDOW_H
#define OPENGLWINDOW_H

#include <QtGui/QWindow>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLExtraFunctions>
#include <QQuickView>

QT_BEGIN_NAMESPACE
class QPainter;
class QOpenGLContext;
class QOpenGLPaintDevice;
QT_END_NAMESPACE

class Openglwindow : public QObject, protected QOpenGLExtraFunctions
{
    Q_OBJECT
public:
    explicit Openglwindow();
    ~Openglwindow();

    //基于QPainter渲染
    virtual void render(QPainter *parent);
    //基于opengl渲染
    virtual void render();
    //初始化
    virtual void initialize();
    //设置动画
    void setAnimating(bool animating);
    void setViewportSize(const QSize &size) { m_viewportSize = size; }
    QSize getViewportSize(){ return m_viewportSize; }


public slots:
    //立刻渲染
    void renderNow();
    void renderLater();

private:
    //动画状态位
    bool m_animating;
    QSize m_viewportSize;

    //OpenGL 上下文
    QOpenGLContext *m_context;
    //OpenGL画笔设备，能使用QPainter在上下文里画东西
    QOpenGLPaintDevice *m_device;

    bool needsInitialize;
};

#endif // OPENGLWINDOW_H
